﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BLL;
using Model;

public partial class MembershipCard_EditCard : BasePage
{
    Access access = new Access();
    MembershipCardBO mbo = new MembershipCardBO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            if (GetQeuryString("para") == "update")
            {
                InitData();
            }
            else if (GetQeuryString("para") == "add")
            {
                //this.txtCreateTime.Text = DateTime.Now.ToString("yyyy-MM-dd");
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            if (GetQeuryString("para") == "update")
            {
                Model.MembershipCard menu = GetEntity();
                menu.ID = Convert.ToInt32(GetQeuryString("id"));
                mbo.Update(menu);
                AlertAndCloseAndReloadParendDataGrid("保存成功！", "grid");
            }
            else if (GetQeuryString("para") == "add")
            {
                Model.MembershipCard m = GetEntity();
                mbo.Add(m);
                AlertAndCloseAndReloadParendDataGrid("保存成功！", "grid");
            }
        }
        catch (Exception)
        {
            AlertMessage("请将信息填写完整");
        }
    }

    private void InitData()
    {
        string id = GetQeuryString("id");
        MembershipCard ds = mbo.GetModel(int.Parse(id)) ;
        //DataRow dr = ds.Tables[0].Rows[0];
        //this.txtMenuName.Text = dr["MenuName"].ToString();
        //this.txtMenuIcon.Text = dr["MenuIcon"].ToString();
        //this.txtMenuUrl.Text = dr["MenuUrl"].ToString();
        //this.txtCreateTime.Text = Convert.ToDateTime(dr["CreateTime"]).ToString("yyyy-MM-dd");
        //this.txtUpdateTime.Text = Convert.ToDateTime(dr["UpdateTime"]).ToString("yyyy-MM-dd");
        //this.txtSequnce.Text = dr["suqence"].ToString();
        
        txtTitle.Text = ds.Title;
        content1.InnerText = ds.Explain;
    }
    public Model.MembershipCard GetEntity()
    {
        Model.MembershipCard m = new Model.MembershipCard();
        m.CreateDate = DateTime.Now;
        m.Explain = content1.InnerText;
        m.Title = txtTitle.Text;
        m.Type = 2;
        m.MID = CurrentUserInfo.MID;
        return m;
    }
}